<!DOCTYPE html>












  


<html class="theme-next muse use-motion" lang="zh-CN">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">






















<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.7.0">

<link rel="stylesheet" href="/css/main.css?v=7.1.2">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=7.1.2">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=7.1.2">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=7.1.2">


  <link rel="mask-icon" href="/images/logo.svg?v=7.1.2" color="#222">







<script id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    version: '7.1.2',
    sidebar: {"position":"left","display":"post","offset":12,"onmobile":false,"dimmer":false},
    back2top: true,
    back2top_sidebar: false,
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="随着功能不断增加，不断迭代更新，React应用会越来越臃肿了，性能也将随之下降。本文从打包和运行两个方面着手，谈谈React应用改如何优化。">
<meta name="keywords" content="React,优化">
<meta property="og:type" content="article">
<meta property="og:title" content="React应用优化">
<meta property="og:url" content="https://qimajiang.com/2018/11/21/React应用优化/index.html">
<meta property="og:site_name" content="启码匠 - 磨刀霍霍向编程">
<meta property="og:description" content="随着功能不断增加，不断迭代更新，React应用会越来越臃肿了，性能也将随之下降。本文从打包和运行两个方面着手，谈谈React应用改如何优化。">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://camo.githubusercontent.com/d819eb6ed893a849f0a83e1cb0b69a2c37e768b4/68747470733a2f2f73692e6765696c6963646e2e636f6d2f687a5f696d675f303864623030303030313561333536326361363830613032363836305f3830305f3438365f756e61646a7573742e706e67">
<meta property="og:updated_time" content="2019-06-24T06:11:04.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="React应用优化">
<meta name="twitter:description" content="随着功能不断增加，不断迭代更新，React应用会越来越臃肿了，性能也将随之下降。本文从打包和运行两个方面着手，谈谈React应用改如何优化。">
<meta name="twitter:image" content="https://camo.githubusercontent.com/d819eb6ed893a849f0a83e1cb0b69a2c37e768b4/68747470733a2f2f73692e6765696c6963646e2e636f6d2f687a5f696d675f303864623030303030313561333536326361363830613032363836305f3830305f3438365f756e61646a7573742e706e67">





  
  
  <link rel="canonical" href="https://qimajiang.com/2018/11/21/React应用优化/">



<script id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>React应用优化 | 启码匠 - 磨刀霍霍向编程</title>
  












  <noscript>
  <style>
  .use-motion .motion-element,
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-title { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">启码匠 - 磨刀霍霍向编程</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
      
        <h1 class="site-subtitle" itemprop="description">磨刀霍霍向编程</h1>
      
    
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">

    
    
    
      
    

    

    <a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">

    
    
    
      
    

    

    <a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>归档</a>

  </li>

      
      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>搜索</a>
        </li>
      
    </ul>
  

  
    

  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



  



</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://qimajiang.com/2018/11/21/React应用优化/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="启码匠">
      <meta itemprop="description" content="学习如磨刀， 需要不断温故。">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="启码匠 - 磨刀霍霍向编程">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">React应用优化

              
            
          </h2>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2018-11-21 15:48:00" itemprop="dateCreated datePublished" datetime="2018-11-21T15:48:00+08:00">2018-11-21</time>
            

            
              

              
                
                <span class="post-meta-divider">|</span>
                

                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2019-06-24 14:11:04" itemprop="dateModified" datetime="2019-06-24T14:11:04+08:00">2019-06-24</time>
              
            
          </span>

          

          
            
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>随着功能不断增加，不断迭代更新，React应用会越来越臃肿了，性能也将随之下降。本文从打包和运行两个方面着手，谈谈React应用改如何优化。</p>
<a id="more"></a>

<h1 id="一、webpack打包优化"><a href="#一、webpack打包优化" class="headerlink" title="一、webpack打包优化"></a>一、webpack打包优化</h1><h2 id="1、缓存node-moduels"><a href="#1、缓存node-moduels" class="headerlink" title="1、缓存node_moduels"></a>1、缓存<code>node_moduels</code></h2><p>我公司的项目每次上线部署的时候，虽然说都要要Jenkins上，但项目越来越多，每个项目部署占用时间都很长，导致每次部署完一个环境的所有项目耗费很多时间。</p>
<p>如果将同一项目的<code>node_mudules</code>在每次打包完毕后缓存起来，下次打包前先判断是否与上次<code>node_moduels</code>相同。若相同，则直接使用上次缓存的<code>node_modules</code>,否则才重新安装依赖包。</p>
<p>那该如何实现上面所说的逻辑？</p>
<ul>
<li>检查<code>packages.json</code>的 <code>md5</code>；</li>
<li>打包完成后以该次<code>packages.json</code>的<code>md5</code>值作为文件名，压缩<code>node_modules</code>并缓存到指定位置；</li>
<li>下次打包前，同样先检查当次<code>packages.json</code>的 <code>md5</code>，若相同直接使用上次的<code>node_moduels</code>;</li>
</ul>
<p>具体的SHELL如下：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#!/bin/bash</span></span><br><span class="line">PKG_SUM=$(md5sum package.json | cut -d\  -f <span class="number">1</span>)</span><br><span class="line">NPM_TARBALL_CACHE=$&#123;HOME&#125;/.cache/ReactCache/npmtarball/reactSPA</span><br><span class="line">NPM_TARBALL=node_modules-$&#123;PKG_SUM&#125;.tgz</span><br><span class="line">NPM_TARBALL_MD5SUM=$&#123;NPM_TARBALL&#125;.md5sum</span><br><span class="line">		[ ! -e $&#123;NPM_TARBALL_CACHE&#125; ] &amp;&amp; mkdir -p $&#123;NPM_TARBALL_CACHE&#125;</span><br><span class="line">   </span><br><span class="line">    TARBALL=$&#123;NPM_TARBALL_CACHE&#125;/$&#123;NPM_TARBALL&#125;</span><br><span class="line">    TARBALLMD5SUM=$&#123;NPM_TARBALL_CACHE&#125;/$&#123;NPM_TARBALL_MD5SUM&#125; </span><br><span class="line">    echo <span class="string">"checking node modules "</span>$&#123;TARBALL&#125;</span><br><span class="line">    <span class="keyword">if</span> [ ! -f $&#123;TARBALL&#125; ];then          </span><br><span class="line">            echo <span class="string">"package.json has some changes, reinstall node modules"</span></span><br><span class="line">            rm -rf $&#123;NPM_TARBALL_CACHE&#125;<span class="comment">/*</span></span><br><span class="line"><span class="comment">         		yarn</span></span><br><span class="line"><span class="comment">         		echo "yarn success"</span></span><br><span class="line"><span class="comment">         		if [ -d node_modules ];then</span></span><br><span class="line"><span class="comment">         			echo "tar and caching..." </span></span><br><span class="line"><span class="comment">             	tar zcf $&#123;TARBALL&#125; node_modules || return 1</span></span><br><span class="line"><span class="comment">             	md5sum $&#123;TARBALL&#125; &gt; $&#123;TARBALLMD5SUM&#125;</span></span><br><span class="line"><span class="comment">             	echo "checking current MD5."</span></span><br><span class="line"><span class="comment">             	md5sum -c $&#123;TARBALLMD5SUM&#125; || rm -f $&#123;TARBALL&#125; $&#123;TARBALLMD5SUM&#125;  </span></span><br><span class="line"><span class="comment">             	echo "install completed, cached" </span></span><br><span class="line"><span class="comment">       			fi         	     		</span></span><br><span class="line"><span class="comment">    else</span></span><br><span class="line"><span class="comment">    		echo "package.json has no changes, clone previous node modules"</span></span><br><span class="line"><span class="comment">    		if [  -d node_modules ];then</span></span><br><span class="line"><span class="comment">    				echo "node_modules dir existed "$&#123;TARBALL&#125;</span></span><br><span class="line"><span class="comment">    			else</span></span><br><span class="line"><span class="comment">    				echo "unpacking..."	$&#123;TARBALL&#125;    	</span></span><br><span class="line"><span class="comment">    				tar  xzf $&#123;TARBALL&#125;   </span></span><br><span class="line"><span class="comment">    		fi</span></span><br><span class="line"><span class="comment">        </span></span><br><span class="line"><span class="comment">    fi</span></span><br><span class="line"><span class="comment">chmod -R a+rwx node_modules</span></span><br></pre></td></tr></table></figure>

<h2 id="2、加速代码压缩"><a href="#2、加速代码压缩" class="headerlink" title="2、加速代码压缩"></a>2、加速代码压缩</h2><p><code>webpack</code>提供的UglifyJS插件由于采用单线程压缩，速度很慢 ,<br><code>webpack-parallel-uglify-plugin</code>插件可以并行运行<code>UglifyJS</code>插件，这可以有效减少构建时间，当然，该插件应用于生产环境而非开发环境，配置如下：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="keyword">var</span> ParallelUglifyPlugin = <span class="built_in">require</span>(<span class="string">'webpack-parallel-uglify-plugin'</span>);</span><br><span class="line"><span class="keyword">new</span> ParallelUglifyPlugin(&#123;</span><br><span class="line">   cacheDir: <span class="string">'.cache/'</span>,</span><br><span class="line">   uglifyJS:&#123;</span><br><span class="line">     output: &#123;</span><br><span class="line">       comments: <span class="literal">false</span></span><br><span class="line">     &#125;,</span><br><span class="line">     compress: &#123;</span><br><span class="line">       warnings: <span class="literal">false</span></span><br><span class="line">     &#125;</span><br><span class="line">   &#125;</span><br><span class="line"> &#125;)</span><br></pre></td></tr></table></figure>

<h2 id="3、HappyPack加速构建"><a href="#3、HappyPack加速构建" class="headerlink" title="3、HappyPack加速构建"></a>3、<code>HappyPack</code>加速构建</h2><p><code>happypack</code>的原理是让loader可以多进程去处理文件，原理如图示：</p>
<p><img src="https://camo.githubusercontent.com/d819eb6ed893a849f0a83e1cb0b69a2c37e768b4/68747470733a2f2f73692e6765696c6963646e2e636f6d2f687a5f696d675f303864623030303030313561333536326361363830613032363836305f3830305f3438365f756e61646a7573742e706e67" alt=""></p>
<p>目前项目中基本只对js和less文件使用<code>HappyPack</code>加速,具体配置如下：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="keyword">var</span> HappyPack = <span class="built_in">require</span>(<span class="string">'happypack'</span>),</span><br><span class="line">  os = <span class="built_in">require</span>(<span class="string">'os'</span>),</span><br><span class="line">  happyThreadPool = HappyPack.ThreadPool(&#123; <span class="attr">size</span>: os.cpus().length &#125;);</span><br><span class="line"></span><br><span class="line">modules: &#123;</span><br><span class="line">	loaders: [</span><br><span class="line">	  &#123;</span><br><span class="line">        test: <span class="regexp">/\.js|jsx$/</span>,</span><br><span class="line">        loader: <span class="string">'HappyPack/loader?id=jsHappy'</span>,</span><br><span class="line">        exclude: <span class="regexp">/node_modules/</span></span><br><span class="line">      &#125;</span><br><span class="line">	]</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">plugins: [</span><br><span class="line">    <span class="keyword">new</span> HappyPack(&#123;</span><br><span class="line">      id: <span class="string">'jsHappy'</span>,</span><br><span class="line">      cache: <span class="literal">true</span>,</span><br><span class="line">      threadPool: happyThreadPool,</span><br><span class="line">      loaders: [&#123;</span><br><span class="line">        path: <span class="string">'babel'</span>,</span><br><span class="line">        query: &#123;</span><br><span class="line">          cacheDirectory: <span class="string">'.webpack_cache'</span>,</span><br><span class="line">          presets: [</span><br><span class="line">            <span class="string">'es2015'</span>,</span><br><span class="line">            <span class="string">'react'</span></span><br><span class="line">          ]</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;]</span><br><span class="line">    &#125;),</span><br><span class="line">    <span class="comment">//如果有单独提取css文件的话</span></span><br><span class="line">    <span class="keyword">new</span> HappyPack(&#123;</span><br><span class="line">      id: <span class="string">'lessHappy'</span>,</span><br><span class="line">      loaders: [<span class="string">'style'</span>,<span class="string">'css'</span>,<span class="string">'less'</span>]</span><br><span class="line">    &#125;)</span><br><span class="line">  ]</span><br></pre></td></tr></table></figure>

<h2 id="4、DLL-amp-DllReference"><a href="#4、DLL-amp-DllReference" class="headerlink" title="4、DLL&amp; DllReference"></a>4、<code>DLL</code>&amp; <code>DllReference</code></h2><p>针对第三方<code>NPM</code>包，这些包我们并不会修改它，但仍然每次都要在build的过程消耗构建性能，我们可以通过<code>DllPlugin</code>来前置这些包的构建.<br>我们使用<code>dllplugin</code>把第三方的NPM包生成一个名为 <code>manifest.json</code> 的文件，这个文件是用来让 <code>DLLReferencePlugin</code> 映射到相关的依赖上去的。在文件中引入该dll文件即可。<br>其原理是通过引用 <code>dll</code> 的 <code>manifest</code> 文件来把依赖的名称映射到模块的 id 上，之后再在需要的时候通过内置的 <code>__webpack_require__</code> 函数来 <code>require</code> 他们。</p>
<p>但对于<code>antd</code>这样的按需加载UI库，不能放在<code>dll</code>中，否则会全部打包进去，按需加载就无效了。</p>
<p>具体配置如下：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">///dll.entry.js 定义dll的入口</span></span><br><span class="line"><span class="keyword">const</span> DLL_ENTRY = &#123;</span><br><span class="line">	react: [<span class="string">'react'</span>, <span class="string">'react-dom'</span>, <span class="string">'react-router-dom'</span>, <span class="string">'prop-types'</span>],</span><br><span class="line">	echarts: [<span class="string">'echarts'</span>],</span><br><span class="line">	vendor: [<span class="string">'mobx'</span>, <span class="string">'mobx-react'</span>, <span class="string">'axios'</span>],</span><br><span class="line">	db: [<span class="string">'dexie'</span>],</span><br><span class="line">&#125;;</span><br><span class="line"><span class="comment">// 定义需要dll 分离的包名</span></span><br><span class="line"><span class="keyword">const</span> DLL_CHUNKS_NAME = <span class="built_in">Object</span>.keys(DLL_ENTRY);</span><br><span class="line"><span class="built_in">module</span>.exports = &#123; DLL_ENTRY, DLL_CHUNKS_NAME &#125;;</span><br><span class="line"></span><br><span class="line"><span class="comment">//dll.config.js</span></span><br><span class="line"><span class="keyword">const</span> path = <span class="built_in">require</span>(<span class="string">'path'</span>);</span><br><span class="line"><span class="keyword">const</span> webpack = <span class="built_in">require</span>(<span class="string">'webpack'</span>);</span><br><span class="line"><span class="keyword">const</span> dllConstants = <span class="built_in">require</span>(<span class="string">'./dll.entry.js'</span>);</span><br><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">	entry: dllConstants.DLL_ENTRY,</span><br><span class="line">	output: &#123;</span><br><span class="line">		filename: <span class="string">'[name].dll.js'</span>, <span class="comment">// 动态链接库输出的文件名称</span></span><br><span class="line">		path: path.join(__dirname, <span class="string">'../dll'</span>), <span class="comment">// 动态链接库输出路径</span></span><br><span class="line">		libraryTarget: <span class="string">'var'</span>, <span class="comment">// 链接库(react.dll.js)输出方式 默认'var'形式赋给变量 b</span></span><br><span class="line">		library: <span class="string">'_dll_[name]_[hash]'</span> <span class="comment">// 全局变量名称 导出库将被以var的形式赋给这个全局变量 通过这个变量获取到里面模块</span></span><br><span class="line">	&#125;,</span><br><span class="line">	plugins: [</span><br><span class="line">		<span class="keyword">new</span> webpack.DllPlugin(&#123;</span><br><span class="line">			<span class="comment">// path 指定manifest文件的输出路径</span></span><br><span class="line">			path: path.join(__dirname, <span class="string">'../dll'</span>, <span class="string">'[name].manifest.json'</span>),</span><br><span class="line">			context: __dirname,</span><br><span class="line">			name: <span class="string">'_dll_[name]_[hash]'</span> <span class="comment">// 和library 一致，输出的manifest.json中的name值</span></span><br><span class="line">		&#125;)</span><br><span class="line">	]</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="comment">//dll.utils.js</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> path = <span class="built_in">require</span>(<span class="string">'path'</span>);</span><br><span class="line"><span class="keyword">const</span> constants = <span class="built_in">require</span>(<span class="string">'../conf/dll.js'</span>);</span><br><span class="line"><span class="keyword">const</span> webpack = <span class="built_in">require</span>(<span class="string">'webpack'</span>);</span><br><span class="line"><span class="keyword">const</span> CopyWebpackPlugin = <span class="built_in">require</span>(<span class="string">'copy-webpack-plugin'</span>);</span><br><span class="line"><span class="keyword">const</span> HtmlIncludeAssetsPlugin = <span class="built_in">require</span>(<span class="string">'html-webpack-include-assets-plugin'</span>);</span><br><span class="line"><span class="comment">//创建 dll 的关联包，返回[]</span></span><br><span class="line"><span class="comment">// 当我们需要使用动态链接库时 首先会找到manifest文件 得到name值记录的全局变量名称 然后找到动态链接库文件 进行加载</span></span><br><span class="line"><span class="keyword">const</span> createDllReferences = <span class="function"><span class="params">()</span> =&gt;</span> &#123;</span><br><span class="line">	<span class="keyword">const</span> dllChunks = constants.DLL_CHUNKS_NAME;</span><br><span class="line">	<span class="keyword">const</span> tmpArr = [];</span><br><span class="line">	dllChunks.forEach(<span class="function"><span class="params">item</span> =&gt;</span> &#123;</span><br><span class="line">		tmpArr.push(</span><br><span class="line">			<span class="keyword">new</span> webpack.DllReferencePlugin(&#123;</span><br><span class="line">				manifest: <span class="built_in">require</span>(path.join(__dirname, <span class="string">`../../dll/<span class="subst">$&#123;item&#125;</span>.manifest.json`</span>)) <span class="comment">//)</span></span><br><span class="line">			&#125;)</span><br><span class="line">		);</span><br><span class="line">	&#125;);</span><br><span class="line">	<span class="keyword">return</span> tmpArr;</span><br><span class="line">&#125;;</span><br><span class="line"><span class="comment">//copy dll 的文件到输出目录</span></span><br><span class="line"><span class="keyword">const</span> copyDllToAssets = <span class="function"><span class="params">()</span> =&gt;</span> &#123;</span><br><span class="line">	<span class="keyword">const</span> dllChunks = constants.DLL_CHUNKS_NAME;</span><br><span class="line">	<span class="keyword">const</span> tmpArr = [];</span><br><span class="line">	dllChunks.forEach(<span class="function"><span class="params">item</span> =&gt;</span> &#123;</span><br><span class="line">		tmpArr.push(&#123; <span class="attr">from</span>: <span class="string">`dll/<span class="subst">$&#123;item&#125;</span>.dll.js`</span>, <span class="attr">to</span>: <span class="string">'dll'</span> &#125;);</span><br><span class="line">	&#125;);</span><br><span class="line">	<span class="keyword">return</span> <span class="keyword">new</span> CopyWebpackPlugin(tmpArr);</span><br><span class="line">&#125;;</span><br><span class="line"><span class="comment">//对dll资源添加相对html的路径</span></span><br><span class="line"><span class="keyword">const</span> addDllHtmlPath = <span class="function"><span class="params">()</span> =&gt;</span> &#123;</span><br><span class="line">	<span class="keyword">const</span> dllChunks = constants.DLL_CHUNKS_NAME;</span><br><span class="line">	<span class="keyword">const</span> tmpArr = [];</span><br><span class="line">	dllChunks.forEach(<span class="function"><span class="params">item</span> =&gt;</span> &#123;</span><br><span class="line">		tmpArr.push(<span class="string">`dll/<span class="subst">$&#123;item&#125;</span>.dll.js`</span>);</span><br><span class="line">	&#125;);</span><br><span class="line">	<span class="keyword">return</span> <span class="keyword">new</span> HtmlIncludeAssetsPlugin(&#123;</span><br><span class="line">		assets: tmpArr, <span class="comment">// 添加的资源相对html的路径</span></span><br><span class="line">		append: <span class="literal">false</span> <span class="comment">// false 在其他资源的之前添加 true 在其他资源之后添加</span></span><br><span class="line">	&#125;);</span><br><span class="line">&#125;;</span><br><span class="line"><span class="built_in">module</span>.exports = &#123; createDllReferences, copyDllToAssets, addDllHtmlPath &#125;;</span><br></pre></td></tr></table></figure>

<p>然后在<code>build.config.js</code>中加入dll插件：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">dllUtils.copyDllToAssets(),</span><br><span class="line">...dllUtils.createDllReferences(),</span><br><span class="line">dllUtils.addDllHtmlPath(),</span><br></pre></td></tr></table></figure>

<h2 id="5、缓存dll"><a href="#5、缓存dll" class="headerlink" title="5、缓存dll"></a>5、缓存<code>dll</code></h2><p>对于上文所说的，使用dll抽离第三方npm库可以加速打包，但还存在一种情况就是，dll可能很久不会改变，那每次<code>build</code>的时候都要重新生成dll包，要不然每次收到复制到指定目录。</p>
<p>参考<code>node_modules</code>的缓存机制，我们可以将生成的<code>dll</code>包缓存起来，每次检查对象<code>dll.entry.js</code>的<code>md5</code>值，只要dll的入口定义不变则认为无需生成新的dll包。具体配置就不写了，跟上面的差不多。</p>
<h2 id="6、其他"><a href="#6、其他" class="headerlink" title="6、其他"></a>6、其他</h2><ul>
<li>开启<code>devtool: &quot;#inline-source-map&quot;</code>会增加编译时间</li>
<li><code>DedupePlugin</code>插件可以在打包的时候删除重复或者相似的文件，实际测试中应该是文件级别的重复的文件</li>
<li>减少构建搜索或编译路径</li>
<li>缓存与增量构建:<code>babel-loader</code>可以缓存处理过的模块，对于没有修改过的文件不会再重新编译，<code>cacheDirectory</code>有着2倍以上的速度提升，这对于rebuild 有着非常大的性能提升。</li>
</ul>
<h1 id="二、React运行优化"><a href="#二、React运行优化" class="headerlink" title="二、React运行优化"></a>二、React运行优化</h1><h2 id="1、组件懒加载"><a href="#1、组件懒加载" class="headerlink" title="1、组件懒加载"></a>1、组件懒加载</h2>
      
    </div>

    

    
    
    

    

    
      
    
    

    

    <footer class="post-footer">
      
        
          
        
        <div class="post-tags">
          
            <a href="/tags/React/" rel="tag"># React</a>
          
            <a href="/tags/优化/" rel="tag"># 优化</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/10/25/浏览器持久化存储那些事/" rel="next" title="浏览器持久化存储那些事">
                <i class="fa fa-chevron-left"></i> 浏览器持久化存储那些事
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>


  </div>


          </div>
          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">启码匠</p>
              <div class="site-description motion-element" itemprop="description">学习如磨刀， 需要不断温故。</div>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/archives/">
                
                    <span class="site-state-item-count">34</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>
              

              

              
                
                
                <div class="site-state-item site-state-tags">
                  
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">47</span>
                    <span class="site-state-item-name">标签</span>
                  
                </div>
              
            </nav>
          

          

          

          

          

          
          

          
            
          
          

        </div>
      </div>

      
      <!--noindex-->
        <div class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
            
            
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#一、webpack打包优化"><span class="nav-number">1.</span> <span class="nav-text">一、webpack打包优化</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1、缓存node-moduels"><span class="nav-number">1.1.</span> <span class="nav-text">1、缓存node_moduels</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2、加速代码压缩"><span class="nav-number">1.2.</span> <span class="nav-text">2、加速代码压缩</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3、HappyPack加速构建"><span class="nav-number">1.3.</span> <span class="nav-text">3、HappyPack加速构建</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4、DLL-amp-DllReference"><span class="nav-number">1.4.</span> <span class="nav-text">4、DLL&amp; DllReference</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5、缓存dll"><span class="nav-number">1.5.</span> <span class="nav-text">5、缓存dll</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6、其他"><span class="nav-number">1.6.</span> <span class="nav-text">6、其他</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#二、React运行优化"><span class="nav-number">2.</span> <span class="nav-text">二、React运行优化</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1、组件懒加载"><span class="nav-number">2.1.</span> <span class="nav-text">1、组件懒加载</span></a></li></ol></li></ol></div>
            

          </div>
        </div>
      <!--/noindex-->
      

      

    </div>
  </aside>
  


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">启码匠</span>

  

  
</div>


  <div class="powered-by">由 <a href="https://hexo.io" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v3.9.0</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 – <a href="https://theme-next.org" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> v7.1.2</div>




        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  

  

  
</div>









        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

    

    
  </div>

  

<script>
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  <script src="/lib/jquery/index.js?v=3.4.1"></script>

  
  <script src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>


  


  <script src="/js/utils.js?v=7.1.2"></script>

  <script src="/js/motion.js?v=7.1.2"></script>



  
  


  <script src="/js/schemes/muse.js?v=7.1.2"></script>



  
  <script src="/js/scrollspy.js?v=7.1.2"></script>
<script src="/js/post-details.js?v=7.1.2"></script>



  


  <script src="/js/next-boot.js?v=7.1.2"></script>


  

  

  

  


  


  
  <script>
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url).replace(/\/{2,}/g, '/');
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x"></i></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x"></i></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  

  

  

  

  

  

  

  

  

  

  

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"log":false,"model":{"jsonPath":"/live2dw/assets/shizuku.model.json"},"display":{"position":"left","width":150,"height":300},"mobile":{"show":true}});</script></body>
</html>
